﻿using mediaControl.Vo;
using Prism.Events;
using Prism.Mvvm;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace mediaControl.ViewModels
{
    public class WebBrowserViewModel : BindableBase
    {
        //事件聚合器
        private readonly IEventAggregator _eventAggregator;

        private List<ProgramItem> currentProgramList;

        private string cycleModel;
        public WebBrowserViewModel(DialogParameters parameters, IEventAggregator eventAggregator)
        {
            currentProgramList = new List<ProgramItem>();
            List<PlaySourceVo> playSourceVos = parameters.GetValue<List<PlaySourceVo>>("source");
            cycleModel = parameters.GetValue<string>("cycleModel");
            foreach (PlaySourceVo playSourceVo in playSourceVos)
            {
                currentProgramList.Add(playSourceVo.SouceItem);
            }
            WebUrl = currentProgramList[0].ItemPath;
            foreach (Window win in Application.Current.Windows)
            {
                WebBrowser webBrowser = win.FindName("web") as WebBrowser;
                if (webBrowser != null)
                {
                    webBrowser.Source = new Uri(WebUrl);

                    break;
                }
            }
            _eventAggregator = eventAggregator;
        }
        private string webUrl;

        public string WebUrl { get { return webUrl; } set { this.webUrl = value; RaisePropertyChanged(); } }
    }
}
